package com.working.home.ui.search

import androidx.appcompat.widget.SearchView
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.working.home.data.remote.HomeServices
import com.working.libbase.model.ArticleResponse
import com.working.libcommon.adapter.PagingDataSource

class SearchViewModel(private val homeServices: HomeServices) : ViewModel() {

    val searchKey = MutableLiveData<String>()

    val queryTextListener = object : SearchView.OnQueryTextListener {
        override fun onQueryTextSubmit(query: String?): Boolean {
            searchKey.postValue(query)
            return false
        }

        override fun onQueryTextChange(newText: String?): Boolean {
            return false
        }
    }


    val dataSource: PagingDataSource<ArticleResponse> = PagingDataSource {
        searchKey.value?.let { it1 -> homeServices.search(it.pageNo, it1).data?.datas }
    }


    private fun onSearch(query: String?) {

    }
}
